package name.zxw.rabbitmq.workqueues;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Delivery;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @author ZhangXinWang
 * @date 2022/6/17 2:46
 */
public class Worker04 {

    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("guest");
        factory.setPassword("guest");
        Channel channel = factory.newConnection().createChannel();

        channel.basicConsume("ask_queue", false,
                (String consumerTag, Delivery message) -> {
                    System.out.println("C2:" + new String(message.getBody()));
                    try {
                        TimeUnit.SECONDS.sleep(30);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
                }, (String consumerTag) -> {
                    System.out.println("C2 error");
                }
        );

    }


}
